
from chaotic import chaotic
from mbg import join, bottom, top, assign, iota

succ = {1: set([2, 3]),
        2: set([4]),
        3: set([4]),
        4: set([5, 6]),
        5: set([4]),
        6: set([7]),
        7: set([8]),
        8: set()
        }

tr = {(1,2): lambda ng: ng,
      (1,3): lambda ng: ng,
      (2,4): lambda ng: assign(ng, 'x', ('5', ())),
      (3,4): lambda ng: assign(ng, 'x', ('7', ())),
      (4,5): lambda ng: ng,
      (4,6): lambda ng: ng,
      (5,4): lambda ng: assign(ng, 'y', ('x', ())),
      (6,7): lambda ng: assign(ng, 'z', ('+', (('y',()), ('x',())))),
      (7,8): lambda ng: assign(ng, 't', ('z', ())),
      }

tr_txt = {(1,2): "if (getc()) (then)",
          (1,3): "if (getc()) (else)",
          (2,4): "x = 5;",
          (3,4): "x = 7;",
          (4,5): "while (1) do",
          (4,6): "while (1) do (end while)",
          (5,4): "y = x;",
          (6,7): "z = y + x;",
          (7,8): "t = z"
          }

chaotic(succ, 1, iota, join, bottom, tr, tr_txt, "ng_prog1.png")

#1. if (getc()):
#2.    x = 5;
#   else:
#3.    x = 7;
#4. while (1) do 
#5.    y = x;
#6. z = y + x;
#7. t = z;